package com.thinkgem.jeesite.frame.pm.utils;

import com.thinkgem.jeesite.common.utils.CacheUtils;
import com.thinkgem.jeesite.frame.pm.entity.PmDataDictItem;
import com.thinkgem.jeesite.frame.pm.entity.PmDataTreeItem;
import com.thinkgem.jeesite.frame.pm.entity.PmParam;

import java.util.List;

/**
 * @Author:Kongxiangsheng
 * @DesCription:
 * @Date:Created in 9:02 2018/9/4
 * @Modified By:
 */
public class PmCacheUtils extends CacheUtils {
    private static final String DATA_DICT_ITEM_CACHE = "dataDictItem_";
    private static final String DATA_TREE_ITEM_CACHE = "dataTreeItem_";
    private static final String PARAM_CACHE = "param_";
    private static final String PM_CACHE = "pmCache";

    // ################# 字典缓存--begin##################

    /**
     * 根据dictCode从缓存获取字典条目列表
     *
     * @param dataDictCode
     * @return
     */
    public static List<PmDataDictItem> getDataDictItems(String dataDictCode) {
        return (List<PmDataDictItem>) getCache(PM_CACHE).get(getKey(DATA_DICT_ITEM_CACHE + dataDictCode));
    }

    /**
     * 往缓存中存入某dictCode字典条目列表
     *
     * @param dataDictCode
     * @param dataDictItemList
     */
    public static void putDataDictItems(String dataDictCode, List<PmDataDictItem> dataDictItemList) {
        getCache(PM_CACHE).put(getKey(DATA_DICT_ITEM_CACHE + dataDictCode), dataDictItemList);
    }

    /**
     * 清空缓存中某dictCode的字典条目列表
     *
     * @param dataDictCode
     */
    public static void removeDataDictItems(String dataDictCode) {
        getCache(PM_CACHE).remove(getKey(DATA_DICT_ITEM_CACHE + dataDictCode));
    }

    // ################# 树形字典缓存--begin##################

    /**
     * 根据treeCode从缓存获取字典条目列表
     *
     * @param dataTreeCode
     * @return
     */
    public static List<PmDataTreeItem> getDataTreeItems(String dataTreeCode) {
        return (List<PmDataTreeItem>) getCache(PM_CACHE).get(getKey(DATA_TREE_ITEM_CACHE + dataTreeCode));
    }

    /**
     * 往缓存中存入某treeCode字典条目列表
     *
     * @param dataTreeCode
     * @param dataTreeItemList
     */
    public static void putDataTreeItems(String dataTreeCode, List<PmDataTreeItem> dataTreeItemList) {
        getCache(PM_CACHE).put(getKey(DATA_TREE_ITEM_CACHE + dataTreeCode), dataTreeItemList);
    }

    /**
     * 清空缓存中某treeCode的字典条目列表
     *
     * @param dataTreeCode
     */
    public static void removeDataTreeItems(String dataTreeCode) {
        getCache(PM_CACHE).remove(getKey(DATA_TREE_ITEM_CACHE + dataTreeCode));
    }

    // ################# 参数缓存--begin##################

    /**
     * 根据paramCode获取参数信息
     *
     * @param paramCode
     * @return
     */
    public static PmParam getPmParam(String paramCode) {
        return (PmParam) getCache(PM_CACHE).get(getKey(PARAM_CACHE + paramCode));
    }

    /**
     * 往缓存中存入某paramCode的参数信息
     *
     * @param paramCode
     * @param pmParam
     */
    public static void putPmParam(String paramCode, PmParam pmParam) {
        getCache(PM_CACHE).put(getKey(PARAM_CACHE + paramCode), pmParam);
    }

    /**
     * 清空缓存中某paramCode的参数信息
     *
     * @param paramCode
     */
    public static void removePmParam(String paramCode) {
        getCache(PM_CACHE).remove(getKey(PARAM_CACHE + paramCode));
    }

}
